package com.dapeis.web.wx.wx.demo;

import java.util.Map;

import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpMessageHandler;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage;

import org.springframework.stereotype.Component;

import com.ag.utils.FileUtils;

/**
 * Created by qianjia on 15/1/22.
 */
@Component
public class DemoCustomHandler implements WxMpMessageHandler {
  @Override
  public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService,
      WxSessionManager sessionManager) throws WxErrorException {
	  
      	String wxUrl = "";
	  String content = wxMessage.getContent();
	  if("to".equals(content)) {
		  String href = "<a href=\"" + FileUtils.splicePaths(wxUrl,"v1/order/test") + "\">Order Test</a>";
		  WxMpCustomMessage m = WxMpCustomMessage
		          .TEXT()
		          .toUser(wxMessage.getFromUserName())
		          .content(href)
		          .build();
			    
	      wxMpService.customMessageSend(m);
	  }
	  return null;
  }
}
